﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities;
using DAL;
using Entities.IRepository;

namespace QuanLyBilliards_Coffee
{
    public partial class FormThongKeBangChay : Form
    {
        IHangHoaRepository hh = new HangHoaRepository();
        IChiTietHoaDonRepository ict = new ChiTietHoaDonRepository();
        public FormThongKeBangChay()
        {
            InitializeComponent();
        }
        private void LoadListview(List<DoiTuongThongKe> ds)
        {
            int i = 1;
            lvbanchay.Items.Clear();
            foreach (var item in ds)
            {
                ListViewItem items = new ListViewItem(i + "");
                items.SubItems.Add(item.MaHH);
                HangHoa hhoa = hh.GetByMaHangHoa(item.MaHH);
                items.SubItems.Add(hhoa == null ? "Không Có Tên" : hhoa.TenHH);
                items.SubItems.Add(item.SoLuong+"");
                items.SubItems.Add(item.Tien + " VNĐ");
                lvbanchay.Items.Add(items);
                i++;
            }

        }

        private void FormThongKeBangChay_Load(object sender, EventArgs e)
        {
            LoadListview(ict.getDoiTuongThongKe().OrderByDescending(x => x.SoLuong).Skip(0).Take(5).ToList());
            //var ds = from k in ict.getDoiTuongThongKe() group k by k.MaHH;
         
        }

        private void bttBanChay_Click(object sender, EventArgs e)
        {
            LoadListview(ict.getDoiTuongThongKe().OrderByDescending(x => x.SoLuong).Skip(0).Take(10).ToList());
        }

        private void bttBanCham_Click(object sender, EventArgs e)
        {
            LoadListview(ict.getDoiTuongThongKe().OrderBy(x => x.SoLuong).Skip(0).Take(10).ToList());
        }
    }
}
